﻿//格式化字符串
$.format = function(source, params) {
        if (arguments.length == 1)
            return function() {
                var args = $.makeArray(arguments);
                args.unshift(source);
                return $.format.apply(this, args);
            };
        if (arguments.length > 2 && params.constructor != Array) {
            params = $.makeArray(arguments).slice(1);
        }
        if (params.constructor != Array) {
            params = [params];
        }
        $.each(params, function(i, n) {
            source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
        });
        return source;
    };

var now = new Date();//获取当前时间
var nowString;//时间字符串

function myClock(clockDiv){
	var now = new Date();//获取当前时间
	var nowYear = now.getYear();//年
	var nowMonth = now.getMonth()+1;//月
	var nowDate = now.getDate();//日
	var nowWeek = "日一二三四五六".charAt(now.getDay());//星期
	var nowHours = now.getHours();//时
	var nowMinutes = now.getMinutes();//分
	var nowSeconds = now.getSeconds();//秒
	nowString = $.format("现在的时间是：{0}年{1}月{2}日，星期{3}，{4}时{5}分{6}秒",nowYear,nowMonth,nowDate,nowWeek,nowHours,nowMinutes,nowSeconds);
	$("#"+clockDiv).text(nowString);
	setTimeout("myClock('" + clockDiv + "')",1000);
};

